/* -----------------------------------------------------------------------------
 * PROJECT    : lwf_handlers
 * FILE       : PdfPCellUtil.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Feb 8, 2011  mycodetalks			       Created
 */
package net.lwf.pdf.util;

import java.io.IOException;
import java.net.MalformedURLException;

import lwf.handler.entities.math.SumUtil;
import net.lwf.common.constant.ICommonConstant;
import net.lwf.exception.ExceptionUtil;

import com.itextpdf.text.BadElementException;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;

/**
 * Class description goes here
 */
public class PdfPCellUtil {
	
	public static PdfPCell getEmptyCell() {
		return getEmptyCell(0);
	}
	
	public static PdfPCell getEmptyCell(int colspan) {
		return getEmptyCell(0, colspan);
	}
	
	public static PdfPCell getEmptyCell(int border, int colspan) {
        PdfPCell cell = new PdfPCell(new Phrase(ICommonConstant.SPACE));
        cell.setBorder(border);
        if(colspan != 0) {
        	cell.setColspan(colspan);
        }
        return cell;
	}
	
	public static PdfPCell getCell(String data) {
		return getCell(data, 0);
	}
	
	public static PdfPCell getCell(String data, int border) {
		return getCell(data, border, 0, FontUtil.getDisplayFont());
	}
	
	public static PdfPCell getCell(String data, int border, int colspan) {
		return getCell(data, border, colspan, FontUtil.getDisplayFont());
	}
	
	public static PdfPCell getCell(String data, int border, int colspan, Font font) {
		PdfPCell cell = new PdfPCell(new Phrase(data, font));
		cell.setBorder(border);
		if(colspan != 0) {
			cell.setColspan(colspan);
		}
		return cell;
	}
	
	public static PdfPCell getImageCell(String imagebasepath, String imagename) {
		PdfPCell cell = null;
		boolean exception = false;
		Image jpg = null;
		try {
			jpg = Image.getInstance(imagebasepath + imagename);
		} catch (BadElementException beex) {
			exception = true;
		} catch (MalformedURLException mfuex) {
			exception = true;
		} catch (IOException ioex) {
			exception = true;
		}
		if(!exception) {
			cell = new PdfPCell(jpg);
		}
		else {
			cell = new PdfPCell(new Phrase(ICommonConstant.SPACE));
		}
		
		return cell;
	}

}



